﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Line: MonoBehaviour
{
	[Header("连成线的每个点世界坐标")] public Vector3[] points;

	[Header("流动速度")] public float speed = 1f;

	[Header("线的宽度")] public float width = 0.4f;

	private Material material;

	private float value = 0;

	void Awake()
	{
		InitLine();
	}

	void Update()
	{
		value += speed * 0.01F;
		material.mainTextureOffset = new Vector2(value,0);
	}

	public void InitLine()
	{
		//获取LineRenderer，设置参数
		LineRenderer lineRenderer = gameObject.GetComponent<LineRenderer>();
		lineRenderer.positionCount = points.Length;
		lineRenderer.SetPositions(points);
		lineRenderer.widthMultiplier = width;
		material = lineRenderer.material;
	}
}

